package com.lagou.db;

import com.lagou.zk.DbConfZK;
import org.apache.commons.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;


public class DBCPUtils {

    public static BasicDataSource dataSource;

    public static HashMap<String, String> dbConf = null;


    public static Connection getConnection() throws SQLException {

        return dataSource.getConnection();
    }

    public static void close(Connection conn, Statement statement) {

        if (null != conn && null != statement) {
            try {
                statement.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(Connection conn, Statement statement, ResultSet resultSet) {

        if (null != conn && null != statement && null != resultSet) {
            try {
                resultSet.close();
                statement.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
